import Sprite from '../base/sprite'
import DataBus from '../databus'

const BULLET_IMG_SRC = 'images/bullet.png'
const BULLET_WIDTH = 16
const BULLET_HEIGHT = 30

const __ = {
  speed: Symbol('speed')
}

const databus = new DataBus()

export default class ShotGunBullet extends Sprite {
  constructor() {
    super(BULLET_IMG_SRC, BULLET_WIDTH, BULLET_HEIGHT)
  }

  // theata : 角度，y 轴为 0 度，往右正往左负
  init(x, y, speed, theata) {
    this.x = x
    this.y = y
    this[__.speed] = speed
    const theataTransfer = Math.PI * theata/180.0
    this.xtmp = Math.sin(theataTransfer) * this[__.speed];
    this.ytmp = Math.cos(theataTransfer) * this[__.speed];

    this.visible = true
    this.zim
  }

  // 每一帧更新子弹位置
  update() {

    this.x -= this.xtmp
    this.y -= this.ytmp

    // 超出屏幕外回收自身
    if (this.y < -this.height || this.x < -this.width) {
      databus.removeBullets(this)
    }
  }
}
